package com.upcode.weighing.vo.req.pc;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
@EqualsAndHashCode(callSuper=false)
public class CancelBackOrderQueryReqVo {

    /**
     * 车牌号
     */
    private String vehicleId;
    /**
     * 订单开始时间
     */
    private String orderStartTime;
    /**
     * 订单结束时间
     */
    private String orderEndTime;
    /**
     * 申请单状态 1-待审核 2-注销申请中 3-已办结 4-审核拒绝
     */
    private Integer orderStatus;
    /**
     * 处理开始时间
     */
    private String handleStartTime;
    /**
     * 处理结束时间
     */
    private String handleEndTime;
    /**
     * 申请单类型：1-撤单 2-退货
     */
    private Integer orderType;
    /**
     * 申请单来源。1-新e畅APP 2-部级平台  3-管理平台
     */
    private Integer orderSrc;

    public String checkParams(){
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if(StringUtils.isNotBlank(orderStartTime) && StringUtils.isBlank(orderEndTime)){
            LocalDate nowDate = LocalDate.now();
            orderEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(orderStartTime) && StringUtils.isNotBlank(orderEndTime)){
            LocalDate startDate = LocalDate.parse(orderStartTime, dtf);
            LocalDate endDate = LocalDate.parse(orderEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "订单结束日期不能大于订单开始日期";
            }
            orderStartTime += " 00:00:00";
            orderEndTime += " 23:59:59";
        }
        if(StringUtils.isNotBlank(handleStartTime) && StringUtils.isBlank(handleEndTime)){
            LocalDate nowDate = LocalDate.now();
            handleEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(handleStartTime) && StringUtils.isNotBlank(handleEndTime)){
            LocalDate startDate = LocalDate.parse(handleStartTime, dtf);
            LocalDate endDate = LocalDate.parse(handleEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "处理结束日期不能大于处理开始日期";
            }
            handleStartTime += " 00:00:00";
            handleEndTime += " 23:59:59";
        }
        return null;
    }


}
